<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>图片切换</title>
	</head>
	<body>
		<img src="img/1.jpg" id="img"><br>
		<button type="button" onclick="doswitch()">开始</button>
		<button type="button" onclick="doEnd()">结束</button>
	</body>
	<script type="text/javascript">
	var begin;
		function doswitch(){
			var imgid = document.getElementById('img');
			var num = 0;
			begin = setInterval(function(){
				if(num == 9){
					num = 0;
				}
				num++;
				imgid.src ='img/' + num + '.jpg';
			},100);
		}
		function doEnd(){
			clearInterval(begin);
		}

	</script>
</html>
